package licode.unisop.client.feign;

import licode.unisop.client.info.*;
import licode.unisop.client.utils.SopAuthConst;
import licode.unisop.client.utils.SopResult;
import licode.unisop.client.vo.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * 登录外部调用封装
 *
 * @author licode
 */
@FeignClient(name = "${uni-sop.service:uni-auth-service}", url = "${uni-sop.host:}")
public interface SoUserAuthFeign {
    @PostMapping("/uni-auth/v1/oauth/token")
    SopResult<SopAuthUser> token(
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.TERMINAL_ID) String deviceId,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.CODE) String scope,
            @RequestParam(SopAuthConst.STATE) String state,
            @RequestHeader(SopAuthConst.IP_ADDRESS) String ipAddr,
            @RequestHeader(SopAuthConst.USER_BROWSER) String userBrowser);

    @PostMapping("/uni-auth/v1/oauth/login")
    SopResult<SopAuthUser> login(
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestBody SopAuthIn authAccount,
            @RequestParam(SopAuthConst.TERMINAL_ID) String deviceId,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.CLIENT_ID) String clientId,
            @RequestParam(SopAuthConst.CLIENT_SECRET) String clientSecret,
            @RequestParam(SopAuthConst.GRANT_TYPE) String grantType,
            @RequestParam(SopAuthConst.SCOPE) String scope,
            @RequestParam(SopAuthConst.CAPTCHA_KEY) String captchaKey,
            @RequestParam(SopAuthConst.CAPTCHA_CODE) String captchaCode,
            @RequestHeader(SopAuthConst.IP_ADDRESS) String ipAddr,
            @RequestHeader(SopAuthConst.USER_BROWSER) String userBrowser);

    @PostMapping("/uni-auth/v1/oauth/captcha/code")
    SopResult<Map<String, Object>> getCaptchaCode();

    @PostMapping("/uni-auth/v1/oauth/user/password/update")
    SopResult<String> updatePassword(
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestBody SopUpdatePasswordIn passwordIn,
            @RequestParam(SopAuthConst.TERMINAL_ID) String deviceId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String accessToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId);

    @PostMapping("/uni-auth/v1/oauth/authorize")
    SopResult<SopAuthResult> authorize(
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestBody SopAuthIn authAccount,
            @RequestParam(SopAuthConst.TERMINAL_ID) String deviceId,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.CLIENT_ID) String clientId,
            @RequestParam(SopAuthConst.CLIENT_SECRET) String clientSecret,
            @RequestParam(SopAuthConst.GRANT_TYPE) String grantType,
            @RequestParam(SopAuthConst.SCOPE) String scope,
            @RequestParam(SopAuthConst.CAPTCHA_KEY) String captchaKey,
            @RequestParam(SopAuthConst.CAPTCHA_CODE) String captchaCode);

    @PostMapping("/uni-auth/v1/oauth/refresh")
    SopResult<SopCredential> refresh(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.REFRESH_TOKEN) String rfToken
    );

    @PostMapping("/uni-auth/v1/oauth/logout")
    SopResult<Boolean> logout(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken
    );

    @PostMapping("/uni-auth/v1/oauth/session/logout")
    SopResult<Boolean> logoutSession(
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken
    );

    // -------------------------- 登录后查询相关操作

    @PostMapping("/uni-auth/v1/token/user-assets")
    SopResult<SopUserAssets> getUserAssets(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken);

    @PostMapping("/uni-auth/v1/token/auth-user-info")
    SopResult<SopAuthUser> getAuthUserInfo(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken
    );

    @PostMapping("/uni-auth/v1/token/user-info")
    SopResult<SopUserBrief> getUserInfo(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken
    );

    @PostMapping("/uni-auth/v1/token/auth-brief")
    SopResult<SopAuthBrief> getAuthBrief(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken
    );

    @PostMapping("/uni-auth/v1/token/credential")
    SopResult<SopCredential> getUserCredential(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken
    );

    @PostMapping("/uni-auth/v1/token/valid")
    SopResult<Boolean> tokenValid(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken
    );

    @PostMapping("/uni-auth/v1/token/auth-user-assets")
    SopResult<Map<String, Object>> getAuthUserAssets(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken
    );

    @PostMapping("/uni-auth/v1/token/info")
    SopResult<SopAuthBrief> getTokenInfo(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken
    );

    @PostMapping("/uni-auth/v1/token/match-url")
    SopResult<SopUrlMatch> matchUrl(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken,
            @RequestParam("url") String url
    );

    @PostMapping("/uni-auth/v1/token/sso-match-url")
    SopResult<SopUrlMatch> ssoMatchUrl(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken,
            @RequestParam("url") String url
    );

    @PostMapping("/uni-auth/v1/token/has-role")
    SopResult<Integer> hasRole(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken,
            @RequestBody SiRoleAction info
    );

    @PostMapping("/uni-auth/v1/token/has-permit")
    SopResult<Integer> hasPermit(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken,
            @RequestBody SiPermitAction action);

    @PostMapping("/uni-auth/v1/token/has-authority")
    SopResult<Integer> hasAuthority(
            @RequestParam(SopAuthConst.REALM_ID) String realmId,
            @RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
            @RequestParam(SopAuthConst.ACCESS_TOKEN) String acToken,
            @RequestBody SiAuthorityAction action);
}
